unit info_publik;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, ZConnection,
  StdCtrls, ExtCtrls, ComCtrls;

type
  TInformasi_pub = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Panel1: TPanel;
    Label1: TLabel;
    cbKabkot1: TComboBox;
    Button1: TButton;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Panel2: TPanel;
    Label2: TLabel;
    cbKabkot2: TComboBox;
    Button2: TButton;
    Panel3: TPanel;
    Label3: TLabel;
    cbKabkot3: TComboBox;
    Button3: TButton;
    ZConnection1: TZConnection;
    qryKabkot: TZQuery;
    qryRekapPemilih: TZQuery;
    qryRekapUmur: TZQuery;
    qryRekapPPKPPSTPS: TZQuery;
    qryKode: TZQuery;
    Panel4: TPanel;
    Label4: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure cbKabkot1Change(Sender: TObject);
    procedure cbKabkot2Change(Sender: TObject);
    procedure cbKabkot3Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Informasi_pub: TInformasi_pub;
  sKabkot1, sKabkot2, sKabkot3 : String;

implementation

{$R *.dfm}

procedure TInformasi_pub.FormCreate(Sender: TObject);
var
  kode_kabkot, tampil_kabkot : String;
begin
  //konek konek
  Zconnection1.Connected := true;

  //load query kabkot
  qryKabkot.Active:=false;
  qryKabkot.SQL.Clear;
  qryKabkot.SQL.Text:='SELECT * FROM kabkot ORDER BY KODE';
  qryKabkot.Active:=true;
  qryKabkot.First;

  //clear combobox kabkot
  cbKabkot1.Items.Clear;
  cbKabkot2.Items.Clear;
  cbKabkot3.Items.Clear;

  //isi combobox kabkot
  while(not qryKabkot.Eof) do
  begin
    kode_kabkot := qryKabkot.FieldByName('KODE').AsString;
    tampil_kabkot := qryKabkot.FieldByName('TAMPIL').AsString;

    cbKabkot1.Items.Add(tampil_kabkot);
    cbKabkot2.Items.Add(tampil_kabkot);
    cbKabkot3.Items.Add(tampil_kabkot);

    qryKabkot.Next;
  end;
end;

procedure TInformasi_pub.cbKabkot1Change(Sender: TObject);
var
  selected, query_kabkot:String;
begin
  //set skabkot
  selected := cbKabkot1.Items[cbKabkot1.ItemIndex];
  query_kabkot := 'SELECT KODE FROM kabkot WHERE TAMPIL = '+quotedStr(selected);

  qryKode.Active:=false;
  qryKode.SQL.Clear;
  qryKode.SQL.Text:=query_kabkot;
  qryKode.Active:=true;

  qryKode.First;
  sKabkot1 := qryKode.fieldByName('KODE').AsString;

end;

procedure TInformasi_pub.cbKabkot2Change(Sender: TObject);
var
  selected, query_kabkot:String;
begin
  //set skabkot
  selected := cbKabkot2.Items[cbKabkot2.ItemIndex];
  query_kabkot := 'SELECT KODE FROM kabkot WHERE TAMPIL = '+quotedStr(selected);

  qryKode.Active:=false;
  qryKode.SQL.Clear;
  qryKode.SQL.Text:=query_kabkot;
  qryKode.Active:=true;

  qryKode.First;
  sKabkot2 := qryKode.fieldByName('KODE').AsString;

end;

procedure TInformasi_pub.cbKabkot3Change(Sender: TObject);
var
  selected, query_kabkot:String;
begin
  //set skabkot
  selected := cbKabkot3.Items[cbKabkot3.ItemIndex];
  query_kabkot := 'SELECT KODE FROM kabkot WHERE TAMPIL = '+quotedStr(selected);

  qryKode.Active:=false;
  qryKode.SQL.Clear;
  qryKode.SQL.Text:=query_kabkot;
  qryKode.Active:=true;

  qryKode.First;
  sKabkot3 := qryKode.fieldByName('KODE').AsString;

end;

end.
